package com.yl.common.util

import android.annotation.SuppressLint
import android.app.Application


/**
 * 全局的Application
 */
object AppUtil {
    private var sApplication: Application? = null

    fun setApplication(application: Application) {
        sApplication = application;
    }


    @SuppressLint("PrivateApi")
    fun getApplication(): Application? {
//        if (sApplication == null) {
//            try {
//                sApplication = Class.forName("android.app.ActivityThread")
//                    .getMethod("currentApplication")
//                    .invoke(null, null as Array<Any?>?) as Application
//            } catch (e: IllegalAccessException) {
//                e.printStackTrace()
//            } catch (e: InvocationTargetException) {
//                e.printStackTrace()
//            } catch (e: NoSuchMethodException) {
//                e.printStackTrace()
//            } catch (e: ClassNotFoundException) {
//                e.printStackTrace()
//            }
//        }
        return sApplication
    }
}